import request from '@/utils/request'
import type { CategoryRespnse, AttrResponseData, AttrValue, DelResponse } from './type'
enum API {
  // 获取一级分类
  C1_URL = '/admin/product/getCategory1',
  // 获取二级分类
  C2_URL = '/admin/product/getCategory2/',
  // 获取三级分类
  C3_URL = '/admin/product/getCategory3/',
  // 获取详情
  ATTR_URL = '/admin/product/attrInfoList/',
  // 添加或者修改已有的属性的接口
  ADDORUPDATEATTR_URL = "/admin/product/saveAttrInfo",
  // 删除已有属性
  DELATTR_URL = "/admin/product/deleteAttr/",
}

export const reqC1 = () => request.get<any, CategoryRespnse>(API.C1_URL)
export const reqC2 = (id: number | string) =>
  request.get<any, CategoryRespnse>(API.C2_URL + id)
export const reqC3 = (id: number | string) =>
  request.get<any, CategoryRespnse>(API.C3_URL + id)
export const reqAttr = (
  c1Id: number | string,
  c2Id: number | string,
  c3Id: number | string,
) =>
  request.get<any, AttrResponseData>(
    API.ATTR_URL + c1Id + '/' + c2Id + '/' + c3Id,
  )

// 新增或者修改
export const reqAddUpdateAttr = (data: AttrValue) => {
  return request.post<any, any>(API.ADDORUPDATEATTR_URL, data)
}

// 删除
export const reqDelAttr = (id: number) => request.delete<any, DelResponse>(API.DELATTR_URL + id)
